
var userid=localStorage.getItem("userid");
var usercard=localStorage.getItem("usercard");

var pageNo=1;
var pageCount=10;//每页多少条记录

var order=new Vue({
    el: '#orders',
    data:{
        orders:[],
        downfileurl:sthost+"downloadFile/"
    },
    methods:{
        cancleorder:function (order) {
            //修改订单 取消订单
            mui.showLoading("正在加载中...","div");
            $.ajax({
                url:sthost+"updateOrderState/",
                data:{
                    orderid:order.orderid,
                    ordertype:bunstype,
                    state:6
                },
                success:function (obj) {
                    mui.hideLoading(function(){
                        if(obj.result==0){
                            order.state=6;
                            mui.toast("订单取消成功");
                        }else{
                            mui.toast("订单取消失败");
                        }
                    });

                },
                error:function () {
                    mui.hideLoading(function(){
                        mui.toast("订单取消失败");
                    });
                }
            });
        }
    }
});

mui.init({
    pullRefresh: {
        container: '#pullrefresh',
        down: {
             style:'circle',
            auto:true,
            callback: pulldownRefresh

        },
        up: {
            auto:false,
            contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
            contentnomore:'没有更多数据了',
            callback: pullupRefresh
        }
    }
});

function pulldownRefresh() {
    pageNo=1;
    mui('#pullrefresh').pullRefresh().refresh(true);
     //mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
    $.ajax({
        url:sthost+"getOrderByUserIdAndOrderType",
        data:{
            userid:userid,
            ordertype:11,
            pageNo:pageNo,
            pageCount:pageCount
        },
        success:function (obj) {
            if(obj.result==0){
                order.orders=[];
                console.log(JSON.stringify(obj));
                for(var i in obj.data){
                    var d=obj.data[i]
                    order.orders.push(d);
                }
            }
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            setTimeout(function () {
                mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
            },100);



        },
        error:function(){
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
            setTimeout(function () {
                mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
            },100);

        }

    })
}

$(function () {
    //pulldownRefresh();
})


function pullupRefresh() {
    pageNo+=1;
    mui('#pullrefresh').pullRefresh().refresh(true);
    $.ajax({
        url:sthost+"getOrderByUserIdAndOrderType",
        data:{
            userid:userid,
            ordertype:11,
            pageNo:pageNo,
            pageCount:pageCount
        },
        success:function (obj) {
            if(obj.result==0&&obj.data.length>0){
                console.log(JSON.stringify(obj));
                for(var i in obj.data){
                    var d=obj.data[i];
                    order.orders.push(d);
                }
                mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                // mui('#pullrefresh').pullRefresh().endPullupToRefresh(fa);
            }else{
                pageNo-=1;
                mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
            }

        },
        error:function () {
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
        }

    })
}



